package org.nlp2rdf.navigator.benchmark.pools;

import com.google.common.collect.Sets;
import com.hp.hpl.jena.rdf.model.Resource;
import org.aksw.commons.semweb.sparql.core.ISparqlEndpoint;
import org.nlp2rdf.navigator.benchmark.MySparqlTasks;
import org.nlp2rdf.navigator.benchmark.PoolUtils;
import org.nlp2rdf.navigator.benchmark.Sample;
import org.nlp2rdf.navigator.benchmark.SampleStats;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Random;
import java.util.Set;

/**
 * Created by Claus Stadler
 * Date: Oct 25, 2010
 * Time: 1:07:22 AM
 */
public class SearchPoolFactory
    implements IPoolFactory
{
    private static final Logger logger = LoggerFactory.getLogger(SearchPoolFactory.class);

    private ISparqlEndpoint sparqlEndpoint;
    private Set<String> graphNames;

    public SearchPoolFactory(ISparqlEndpoint sparqlEndpoint, Set<String> graphNames)
    {
        this.sparqlEndpoint = sparqlEndpoint;
        this.graphNames = graphNames;
    }

    @Override
    public Sample<Resource> createPool(Resource id) {
        Set<Resource> positives = MySparqlTasks.getTypedDBpediaCategoryMembers(sparqlEndpoint, graphNames, id);

        Sample<Resource> result = PoolUtils.generateKeywordSearchPool(sparqlEndpoint, graphNames, id.toString(), positives);

        /*
        SampleStats<Resource> stats = SampleStats.create(
                Sample.create(result.getPositives(), null),
                Sets.union(result.getPositives(), result.getNegatives()));
*/
        logger.info("Search result for " + id + ": pos/neg = " + result.getPositives().size() + "/" + result.getNegatives().size());


        return result;
    }
}
